home *** CD-ROM | disk | FTP | other *** search
/ Network CD 1 / Network CD.iso / tbag / 1-10 / tb1 / arc-files / newfd.arc / Screenprint < prev    next >
Text File  |  1986-01-04  |  4KB  |  212 lines

  1. REM  ScreenPrint
  2. REM  Carolyn Scheppner   CBM  04/86
  3. REM
  4. REM  Graphic screen dump to the printer
  5. REM   using exec library calls
  6. REM  Requires exec.bmap
  7. REM  Use Preferences to select options
  8. REM   such as GrayScale and Negative
  9.  
  10. REM  ***  Calling Program  ***
  11.  
  12. REM  Custom Screen, some graphics
  13. w = 320: h = 200: d = 5
  14. SCREEN 1,w,h,d,1
  15. t$=" D = Draw   P = Print   Q = Quit "
  16. WINDOW 1,t$,,,1
  17. PALETTE 0,1,1,1
  18. PALETTE 1,.2,.4,.8
  19.  
  20. GOSUB DrawLines:
  21.  
  22. MainLoop:
  23. k$ = INKEY$
  24. IF k$ = "d" THEN 
  25.    GOSUB DrawLines:
  26. ELSEIF k$ = "p" THEN
  27.    BorderFlag% = 0  'No borders printed
  28.    GOSUB ScreenDump
  29.    REM  Time to read any error msgs
  30.    FOR de = 1 TO 5000: NEXT
  31. ELSEIF k$ = "q" THEN 
  32.    GOTO Quit:
  33. END IF
  34. GOTO MainLoop:
  35.  
  36. Quit:
  37. WINDOW CLOSE 1
  38. SCREEN CLOSE 1
  39. END
  40.  
  41.  
  42. DrawLines:
  43. CLS               
  44. RANDOMIZE  TIMER
  45. FOR k = 1 TO 12
  46.    x1 = 80 + INT(RND(1) * (w - 160)) 
  47.    x2 = 80 + INT(RND(1) * (w - 160))
  48.    y1 = 40 + INT(RND(1) * (h - 100))
  49.    y2 = 40 + INT(RND(1) * (h - 100))
  50.    dx = 2 + INT(RND(1) * 3)
  51.    IF RND(1) < .5 THEN dx = -dx
  52.    dy = 2 + INT(RND(1) * 2)
  53.    IF RND(1) < .5 THEN dy = -dy
  54.    co = 1 + INT(RND(1) * 16)
  55.    nl = 12 + INT(RND(1) * 10) 
  56.    FOR j = 1 TO nl
  57.       LINE (x1,y1)-(x2,y2),co
  58.       x1 = x1 + dx
  59.       x2 = x2 + dx
  60.       y1 = y1 + dy
  61.       y2 = y2 - dy
  62.    NEXT
  63. NEXT
  64. RETURN
  65.  
  66.  
  67. END
  68.  
  69.  
  70. ScreenDump:
  71.  
  72. REM  If first call of this routine 
  73. REM   declare the exec library functions
  74. REM    which return values
  75.  
  76. IF AlreadyDeclared = 0 THEN
  77.  DECLARE FUNCTION AllocSignal%() LIBRARY
  78.  DECLARE FUNCTION AllocMem&()    LIBRARY
  79.  DECLARE FUNCTION FindTask&()    LIBRARY
  80.  DECLARE FUNCTION DoIO&()        LIBRARY
  81.  DECLARE FUNCTION OpenDevice&    LIBRARY
  82.  AlreadyDeclared = 1
  83. END IF
  84.  
  85. REM  Get addresses of the structures
  86.  
  87. sWindow&   = WINDOW(7)
  88. sScreen&   = PEEKL(sWindow& + 46)
  89. sViewPort& = sScreen& + 44
  90. sRastPort& = sScreen& + 84
  91. sColorMap& = PEEKL(sViewPort& + 4)
  92.  
  93. REM  Get Screen width, height, modes 
  94.  
  95. maxWidth%  = PEEKW(sScreen& + 12)
  96. maxHeight% = PEEKW(sScreen& + 14)
  97. viewModes% = PEEKW(sViewPort& + 32)
  98.  
  99. REM Set up parameters for dump command
  100.  
  101. command%  = 11   'Printer command number
  102. srcX% = 0        'Send whole screen
  103. srcY% = 0 
  104. srcWidth%  = maxWidth%
  105. srcHeight% = maxHeight%
  106. destRows& = 0    'Dump will compute
  107. destCols& = 0
  108. special% = &H84  'FullCol | Aspect
  109.  
  110. IF BorderFlag% = 0 THEN  'No Borders
  111.    srcX% = srcX% + 3
  112.    srcY% = srcY% + 11
  113.    srcWidth%  = srcWidth% - 3 - 11
  114.    srcHeight% = srcHeight% - 11 - 3
  115. END IF   
  116.  
  117. LIBRARY "exec.library"
  118.  
  119.  
  120. REM *** CreatePort ***
  121.  
  122. sigBit% =  AllocSignal%(-1)
  123. ClearPublic& = 65537&
  124. msgPort& = AllocMem&(40,ClearPublic&)
  125. IF msgPort& = 0 THEN
  126.    PRINT "Can't allocate msgPort"
  127.    GOTO cleanup4
  128. END IF
  129.  
  130.  
  131. POKE(msgPort& + 8), 4 'Type=NT_MSGPORT
  132. POKE(msgPort& + 9), 0 'Priority 0 
  133. portName$ = "MyPrtPort"+CHR$(0)
  134. POKEL(msgPort& + 10), SADD(portName$)
  135. POKE(msgPort& + 14), 0 'Flags
  136. POKE(msgPort& + 15), sigBit%
  137. sigTask& = FindTask&(0)
  138. POKEL(msgPort& + 16), sigTask&
  139.  
  140. CALL AddPort(msgPort&)  'Add the port 
  141.  
  142.  
  143. REM  *** CreatExtIO ***
  144.  
  145. ioRequest& = AllocMem&(64,ClearPublic&)
  146. IF ioRequest& = 0  THEN
  147.    PRINT "Can't allocate ioRequest"
  148.    GOTO cleanup3
  149. END IF
  150.  
  151. POKE(ioRequest& + 8),5 'Type=NT_MESSAGE
  152. POKE(ioRequest& + 9),0 'Priority 0
  153. POKEL(ioRequest& + 14), msgPort&
  154.  
  155.  
  156. REM  *** Open the Printer Device ***
  157.  
  158. devName$ = "printer.device"+CHR$(0)
  159. pError& = OpenDevice&(SADD(devName$),0,ioRequest&,0)
  160. IF pError& <> 0  THEN
  161.    PRINT "Can't open printer"
  162.    GOTO cleanup2
  163. END IF
  164.  
  165.  
  166. REM  *** Dump the RastPort ***
  167.  
  168. POKEW(ioRequest& + 28), command%
  169. POKEL(ioRequest& + 32), sRastPort&
  170. POKEL(ioRequest& + 36), sColorMap&
  171. POKEL(ioRequest& + 40), viewModes%
  172. POKEW(ioRequest& + 44), srcX%
  173. POKEW(ioRequest& + 46), srcY%
  174. POKEW(ioRequest& + 48), srcWidth%
  175. POKEW(ioRequest& + 50), srcHeight%
  176. POKEL(ioRequest& + 52), destCols&
  177. POKEL(ioRequest& + 56), destRows&
  178. POKEW(ioRequest& + 60), special%
  179.  
  180. ioError& = DoIO&(ioRequest&)
  181. IF ioError& <> 0 THEN
  182.    PRINT "DumpRPort error =" ioError&
  183.    GOTO cleanup1
  184. END IF
  185.  
  186.  
  187. cleanup1:
  188.    REM  *** Close Printer Device ***
  189.    CALL CloseDevice(ioRequest&)
  190.  
  191. cleanup2:
  192.    REM  *** DeleteExtIO ***
  193.    POKE(ioRequest& + 8), &HFF
  194.    POKEL(ioRequest& + 20), &HFFFF
  195.    POKEL(ioRequest& + 24), &HFFFF
  196.    CALL FreeMem(ioRequest&,64)
  197.  
  198. cleanup3:
  199.    REM  *** DeletePort ***
  200.    CALL RemPort(msgPort&)
  201.    POKE(msgPort& + 8), &HFF  
  202.    POKEL(msgPort& + 20), &HFFFF
  203.    CALL FreeSignal(sigBit%)
  204.    CALL FreeMem(msgPort&,40)
  205.    
  206. cleanup4:   
  207.    LIBRARY CLOSE
  208.  
  209. RETURN
  210.    
  211.       
  212.